package cn.spring.framework.redis.core;

import cn.spring.framework.redis.config.LzmhRedisProperties;
import cn.spring.framework.redis.context.RedisCacheContext;
import cn.spring.framework.redis.core.redis.*;
import cn.spring.framework.redis.service.RedisService;

/**
 * @author xingkong
 * @Title:
 * @Description: 缓存操作类的抽象类，将通用方法抽取到这里
 * @date 2021/11/13 21:03
 */
public abstract class AbstractCacheOperator implements CacheOperator {
    /**
     * string类型操作接口
     */
    protected StringOperator stringOperator;

    /**
     * map类型操作接口
     */
    protected MapOperator mapOperator;

    /**
     *list类型操作接口
     */
    protected ListOperator listOperator;

    /**
     *set 类型操作接口
     */
    protected SetOperator setOperator;

    /**
     * 失败降级策略
     */
    protected FailbackCacheOperator failbackCacheOperator;

    protected AbstractCacheOperator(LzmhRedisProperties lzmhRedisProperties, RedisService redisService) {
        this.stringOperator = new RedisStringOperator(lzmhRedisProperties,redisService);
        this.mapOperator = new RedisMapOperator(lzmhRedisProperties,redisService);
        this.listOperator = new RedisListOperator(lzmhRedisProperties,redisService);
        this.setOperator = new RedisSetOperator(lzmhRedisProperties, redisService);
        this.failbackCacheOperator = new FailbackCacheOperator(lzmhRedisProperties, redisService,this);
    }

    /**
     * 预处理操作
     */
    protected void preProcess() {
        RedisCacheContext.getContext().setFuture(null);
    }
}
